""" 异常处理中间件
@Project: Rebar
@File: exception_middleware.py
@Author: hzc
@Date: 2023/3/21 16:56
"""
import traceback

from starlette.requests import Request

from model.db.mapper.log_mapper import add_log
from util import error_res, ErrorCode


class ExceptionHandlerMiddleware:

    def __init__(self, app=None):
        self.app = app

    async def __call__(self, request: Request, call_next):
        """
        捕获 http 处理过程中出现的异常
        :param request:
        :param call_next:
        :return:
        """
        # try:
        return await call_next(request)
        # except Exception as e:
        #     print("middleware/exc", e, e.__traceback__.tb_lineno)
        #     error_info = traceback.format_exc()
        #     add_log(request, error_info)  # 添加错误记录
        #     return error_res(ErrorCode.SERVER)


